package cn.hackcloud.mutithread;

import java.util.concurrent.atomic.AtomicInteger;

class PrintNum implements Runnable {
	AtomicInteger num = new AtomicInteger(0);

	@Override
	public void run() {
		while (true) {
			if (num.get() < 100) {
				System.out.println(Thread.currentThread().getName() + "售票，售票号为：" + num.incrementAndGet());
			} else {
				break;
			}
		}
	}

}

public class TestPrintNum {
	public static void main(String[] args) {
		PrintNum num = new PrintNum();
		Thread thread1 = new Thread(num);
		thread1.setName("线程1");
		thread1.start();
		Thread thread2 = new Thread(num);
		thread2.setName("线程2");
		thread2.start();
	}
}
